<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\UserRelation
 *
 * @property int $uid
 * @property int $upuid
 * @property int $created_at
 * @property-read \App\Models\User $upuser
 * @property-read \App\Models\User $user
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserRelation whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserRelation whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserRelation whereUpuid($value)
 * @mixin \Eloquent
 * @property-read \App\Models\Wallet $wallet
 */
class UserRelation extends Model
{
    protected $table = 'user_relation';
    protected $primaryKey = 'uid';
    protected $guarded = [];

    public $timestamps = false;

    static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::creating(function ($model){
            if (!$model->created_at) $model->created_at = time();
        });
    }

    public function upuser()
    {
        return $this->belongsTo(User::class, 'upuid', 'uid');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'uid');
    }

    public function wallet()
    {
        return $this->hasOne(Wallet::class, 'uid', 'uid');
    }
}
